package de.davidneu.gpxviewer.units 
{
    /**
     * @author david
     */
    public class Units 
    {
    	public static const UNIT_METRIC:uint = 0;
    	public static const UNIT_IMPERIAL:uint = 1;
    	public static const UNIT_NAUTICAL:uint = 2;
    	
    	private static var _instance:Units = new Units();
        private var _currentUnit : uint = 0;
        private var _units:Array;
        
        public function Units()
        {
        	_units = [
        	   new UnitSet('km/h', 'm', 'km', 0.001, 1, 0.001),
        	   new UnitSet('mph', 'ft', 'mi', 0.000621371192, 3.2808399, 0.000621371192),
               new UnitSet('knots', 'ft', 'nmi', 0.000539956803, 3.2808399, 0.000539956803)
        	];
        }

        public function get currentUnitSet():UnitSet
    	{
            return _units[_currentUnit];
        }
        
        public function set currentUnit(currentUnit : uint) : void
        {
            _currentUnit = currentUnit;
        }
        
        public static function getInstance():Units
        {
            return _instance;
        }
        
        public static function convertSpeed(val:Number):Number
        {
        	return _instance.currentUnitSet.convertSpeed(val);
        }
        
        public static function convertHeight(val:Number):Number
        {
            return _instance.currentUnitSet.convertHeight(val);
        }
        
        public static function convertDistance(val:Number):Number
        {
            return _instance.currentUnitSet.convertDistance(val);
        }
        
        public static function viewHeight(val:Number, precision:int = 2):String
        {
            return _instance.currentUnitSet.viewHeight(val, precision);
        }
        
        public static function viewSpeed(val:Number, precision:int = 2):String
        {
            return _instance.currentUnitSet.viewSpeed(val, precision);
        }
        
        public static function viewDistance(val:Number, precision:int = 2):String
        {
            return _instance.currentUnitSet.viewDistance(val, precision);
        }
    }
}